<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            list-style-type: none;
        }
        #home {
            height: 380px;
            width: 600px;
            border: 1px solid black;
            position: absolute;
            top: 10px;
            left: 50%;
            transform: translateX(-50%);
        }
        img {
            height: auto;
            width: 100%;
        }
        ul {
            display: flex;
            justify-content: center;
            position: relative;
            bottom: 0px;
        }
        li {
            height: 30px;
            width: 30px;
            border-radius: 50%;
            margin: 5px;
            background-color: #ccc;
            line-height: 30px;
            text-align: center;
        }
        .show {
            background-color: pink;
        }
    </style>
</head>
<body>
    <div id = "home">
        <img src="./images/1.gif">
        <ul>
            <li class="show">1</li>
            <li>2</li>
            <li>3</li>
            <li>4</li>
            <li>5</li>
        </ul>
    </div>
    <script>
        // 3.图片切换，用js实现之前学习的锚点功能
        const list = document.getElementsByTagName("li")
        const img = document.querySelector("img")

        for (let i = 0; i < 5; i++) {
            list[i].onclick = function () {
                for (let j = 0; j < 5; j++) {
                    list[j].setAttribute("class", "")
                    img.src = `./images/${i+1}.gif`
                }
                list[i].setAttribute("class", "show")
            }
        }


    </script>
</body>
</html>